package model;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.transaction.annotation.Transactional;

@Transactional
public class InitServiece {
	protected static final Logger logger = Logger.getLogger(InitServiece.class);
	
	@Autowired
	private MongoTemplate mongoTemplate;
	
	private void init(){
		logger.debug("Init MongoDb users");
		mongoTemplate.dropCollection(Person.class);
		
		//Create new object
		Person p1 = new Person();
		p1.setFirstName("John");
		p1.setLastName("Smith");
		p1.setMoney(1000.0);
		mongoTemplate.save(p1);
		
		//Create new object
		Person p2 = new Person();
		p2.setFirstName("Jane");
		p2.setLastName("Adam");
		p2.setMoney(2000.0);
		mongoTemplate.save(p2);
				
		//Create new object
		Person p3 = new Person();
		p3.setFirstName("Jefn");
		p3.setLastName("Mayer");
		p3.setMoney(3000.0);
		mongoTemplate.save(p3);
	}
}
